package com.luo.controller;

import com.luo.pojo.Dept;
import com.luo.pojo.Results;
import com.luo.service.impl.DeptServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptServiceImpl deptService;
    @GetMapping
    public Results getDept(){
        log.info("查询部门信息");
       List<Dept> listDept = deptService.getDept();
        return Results.success(listDept);
    }

    @DeleteMapping("/{id}")
    public Results deleteDept(@PathVariable Integer id){
        log.info("删除部门信息{}",id);
        deptService.deleteDept(id);
        return Results.success();
    }

    @PostMapping
    public Results addDept(@RequestBody Dept dept){
        log.info("添加部门信息{}",dept);
        deptService.addDept(dept);
        return Results.success();
    }

    @GetMapping("/{id}")
    public Results getDeptById(@PathVariable Integer id){
        log.info("查询部门信息{}",id);
        Dept dept = deptService.getDeptById(id);
        return Results.success(dept);
    }

    @PutMapping
    public Results updateDept(@RequestBody Dept dept){
        log.info("修改部门信息{}",dept);
        deptService.updateDept(dept);
        return Results.success();
    }
}